package com.base.common.action;

import com.base.common.properties.ConfigLoad;
import com.base.common.properties.PushConfigLoad;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;



/**
 * @Description: 初始化加载Servlet
 * @version 1.0.0
 * @author Kevin Colin
 * @datetime 2015年8月10日下午1:03:35
 */
public class InitServlet extends HttpServlet{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private ConfigLoad configLoad;
	
	private PushConfigLoad pushConfigLoad;
	
	// 初始化加载项
	@Override
	public void init(ServletConfig config) throws ServletException {
		ServletContext servletContext=config.getServletContext();
		WebApplicationContext context=WebApplicationContextUtils.
				getWebApplicationContext(servletContext);
		AutowireCapableBeanFactory factory=context.getAutowireCapableBeanFactory();
		
		// 普通配置文件初始化加载
		configLoad = (ConfigLoad) factory.getBean("configLoad");
		configLoad.init();
		
		// 个推配置文件初始化加载
		pushConfigLoad = (PushConfigLoad) factory.getBean("pushConfigLoad");
		pushConfigLoad.init();
	}
}
